<?php
$img_src = '';
if ( isset($_GET['src']) )
	$img_src = $_GET['src'];
if ( !$img_src )
	exit;
	
$max = 0;
if ( isset($_GET['max']) )
	$max = $_GET['max'];
else
	$max = 80;
	
// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width, $height) = getimagesize($img_src);
$image = imagecreatefromjpeg($img_src);
if ( $width>$max or $height>$max){
	if ( $width>$height ){
		$new_width = $max;
		$Reduction = ( ($new_width * 100)/$width );
		$new_height = ( ($height * $Reduction)/100 );
	}
	else{
		$new_height = $max;
		$Reduction = ( ($new_height * 100)/$height );
		$new_width = ( ($width * $Reduction)/100 );
	}
	// Resample
	$image_p = imagecreatetruecolor($new_width, $new_height);
	imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
	ImageJpeg($image_p);
}
else {
	ImageJpeg($image);
}
?>
